package org.hawk.gwt.ppc.examples.simple;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Simple reflection example:
 * @author alex.bereznevatiy@gmail.com
 *
 */
public class Simple implements EntryPoint {
	private Button clickMeButton;
	public void onModuleLoad() {
		final RootPanel rootPanel = RootPanel.get();

		clickMeButton = new Button();
		rootPanel.add(clickMeButton);
		clickMeButton.setText("Click me!");
		clickMeButton.addClickHandler(new ClickHandler(){
			@SuppressWarnings("unchecked")
			public void onClick(ClickEvent event) {
				try {
					/*
					 * Adding an instances of org.hawk.gwt.ppc.examples.simple.SimpleLabel to the RootPanel.
					 * Notice that we are getting class with Class.forName(), however this is not obligatory, 
					 * just to show the power of preprocessing approach.
					 */
					Class<? extends Label> cls = (Class<? extends Label>)
						Class.forName("org.hawk.gwt.ppc.examples.simple.SimpleLabel");
					rootPanel.add(cls.newInstance());
				}
				catch(Exception ex){
					GWT.log("Error!",ex);
				}
			}
		});
	}
}
